package com.sky.service.user.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.entity.Category;
import com.sky.mapper.user.UserCategoryMapper;
import com.sky.service.user.UserCategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@RequiredArgsConstructor
@Slf4j
@Service
public class UserCategoryServiceImpl extends ServiceImpl<UserCategoryMapper, Category> implements UserCategoryService {
    private final UserCategoryMapper userCategoryMapper;

    @Override
    @Cacheable(value = "category", key = "'list:' + (#type != null ? #type : 'all')")
    public List<Category> findAll(Integer type) {
//        if (type == null){
//            throw new RuntimeException("参数错误");
//        }
        log.info("查询分类，id={}", type);
        return userCategoryMapper.selectList(new QueryWrapper<Category>()
                .eq( "type", type)
                .eq("status", 1));
    }

}
